home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
examples
/
insight
/
plugins
/
mynegate.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
6KB
|
212 lines
; $Id: mynegate.pro,v 1.13 1997/04/22 16:21:58 rob Exp $
;
; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;+
; FILE:
; mynegate.pro
;
; PURPOSE:
; This file contains an example Conditioning PlugIn that does negation.
;
; CONTENTS:
; GENERAL ROUTINES
; pro HandleEventsMyNegate - handle dialog box events
;
; CALLBACK ROUTINES
; fun PromptUserMyNegate - main entry point (creates dialog)
;
; REGISTRATION FUNCTION
; fun MyNegate - registers the PlugIn
;
;-
; *****************************************************************************
; GENERAL ROUTINES
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Handle dialog events.
;
pro HandleEventsMyNegate, sEvent
; Catch errors.
;
CATCH, error
if (error ne 0) then begin
CATCH, /CANCEL
void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=(*psState).wMainBase)
RETURN
endif
; Grab the state pointer from the widget user value.
;
WIDGET_CONTROL, sEvent.top, GET_UVALUE=psState
; Get the parent widget ID.
;
wParent = (*psState).wMainBase
; ========================
; PROCESS EVENTS
; ========================
case (sEvent.id) of
; --------------------------------------
; OK button
; --------------------------------------
(*psState).wOKButton: begin
; Get the type code.
;
size = SIZE((*psState).data)
type = size[size[0] + 1]
; Perform conditioning (negation) if the type is right.
;
if ( ((type ge 1) and (type le 6)) or $
(type eq 9) ) then begin
; Warn the user about byte data.
;
if (type eq 1) then begin
message = 'Byte data will be wrapped rather than negated.'
void = DIALOG_MESSAGE(message, DIALOG_PARENT=wParent)
endif
; Perform the negation.
;
(*psState).data = - (*psState).data
; Set the update flag.
;
(*psState).update = 1B
endif else begin
; Tell the user this type is not supported.
;
message = 'This type is not supported for negation.'
void = DIALOG_MESSAGE(message, DIALOG_PARENT=wParent)
endelse
; Destroy the dialog box.
;
WIDGET_CONTROL, sEvent.top, /DESTROY
end
; --------------------------------------
; Cancel button
; --------------------------------------
(*psState).wCancelButton: begin
; Destroy the dialog box.
;
WIDGET_CONTROL, sEvent.top, /DESTROY
end
; --------------------------------------
; other events
; --------------------------------------
else: ; (do nothing)
endcase
end ; HandleEventsMyNegate
; *****************************************************************************
; CALLBACK ROUTINES
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Main entry point for the PlugIn.
;
function PromptUserMyNegate, $
data, $ ; IN/OUT: the data to condition
GROUP=wGroup, $ ; IN: the widget group leader
_EXTRA=extra ; IN: (for unused keywords)
; Create main base (non-sizable).
;
title = 'Conditioning PlugIn Example - My Negate'
wMainBase = WIDGET_BASE(TITLE=title, GROUP_LEADER=wGroup, $
/COLUMN, /MODAL, /TLB_FRAME_ATTR)
void = WIDGET_LABEL(wMainBase, VALUE='Negate the selected data.')
; Create other widgets.
;
wButtonBase = WIDGET_BASE(wMainBase, /ROW, /ALIGN_RIGHT)
wOKButton = WIDGET_BUTTON(wButtonBase, VALUE=' OK ')
wCancelButton = WIDGET_BUTTON(wButtonBase, VALUE=' Cancel ')
; Create the dialog state.
;
sState = { $
update: 0B, $
data: data, $
wMainBase: wMainBase, $
wOKButton: wOKButton, $
wCancelButton: wCancelButton $
}
; Store the state in a heap variable,
; and the pointer in the widget user value.
;
psState = PTR_NEW(sState, /NO_COPY)
WIDGET_CONTROL, wMainBase, SET_UVALUE=psState
; Realize the dialog box.
;
WIDGET_CONTROL, wMainBase, /REALIZE
; Set modal widget default and cancel buttons.
;
WIDGET_CONTROL, wMainBase, DEFAULT_BUTTON=wOKButton, $
CANCEL_BUTTON=wCancelButton
; Start event loop.
;
XMANAGER, 'PromptUserMyNegate', wMainBase, $
EVENT_HANDLER='HandleEventsMyNegate'
; Grab the data and the 'update' flag, remove the state,
; and return the flag.
;
data = (*psState).data
update = (*psState).update
PTR_FREE, psState
RETURN, update ; (return 1 on success, 0 if nothing done)
end ; PromptUserMyNegate
; *****************************************************************************
; REGISTRATION FUNCTION
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Register the Conditioning PlugIn.
;
function MyNegate
; Return the Conditioning PlugIn Registration Structure.
;
RETURN, { $
type: 'Conditioning_PlugIn', $ ; PlugIn type
title: 'My Negate...', $ ; PlugIn title
purpose: 'Reverse sign of data.', $ ; PlugIn purpose
main_func: 'PromptUserMyNegate', $ ; main callback
version: '5.0', $ ; IDL version
revision: '1.0' $ ; PlugIn version
}
end ; MyNegate
; -----------------------------------------------------------------------------